SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.[DnnProduct_vw_Tabs]
AS
	SELECT     
		T.TabID, 
		T.TabOrder, 
		T.PortalID, 
		T.TabName, 
		T.ParentId, 
		T.[Level], 
		T.TabPath, 
		T.UniqueId, 
		T.VersionGuid, 
		T.DefaultLanguageGuid, 
		T.LocalizedVersionGuid, 
		T.IsVisible, 
		CASE WHEN LEFT(LOWER(T .IconFile), 7) = 'fileid=' THEN
			(SELECT Folder + FileName
				FROM dbo.DnnProduct_Files
				WHERE fileid = CAST((RIGHT(LOWER(T.IconFile), Len(T.IconFile) - 7)) AS int)
			) ELSE T.IconFile 
			END AS IconFile, 
		CASE WHEN LEFT(LOWER(T .IconFileLarge), 7) = 'fileid=' THEN
			(SELECT Folder + FileName
				FROM  dbo.DnnProduct_Files
				WHERE fileid = CAST((RIGHT(LOWER(T.IconFileLarge), Len(T.IconFileLarge) - 7)) AS int)
			) ELSE T.IconFileLarge
			END AS IconFileLarge, 
		T.DisableLink, 
		T.Title, 
		T.Description, 
		T.KeyWords, 
		T.IsDeleted, 
		T.SkinSrc, 
		T.ContainerSrc, 
		T.StartDate, 
		T.EndDate, 
		T.Url, 
		CASE WHEN EXISTS (SELECT 1 FROM dbo.DnnProduct_Tabs T2 WHERE T2.ParentId = T.TabId) THEN 'true' ELSE 'false' END AS HasChildren, 
		T.RefreshInterval, 
		T.PageHeadText, 
		T.IsSecure, 
		T.PermanentRedirect, 
		T.SiteMapPriority, 
		CI.ContentItemID, 
		CI.[Content], 
		CI.ContentTypeID, 
		CI.ModuleID, 
		CI.ContentKey, 
		CI.Indexed, 
		T.CultureCode, 
		T.CreatedByUserID, 
		T.CreatedOnDate, 
		T.LastModifiedByUserID, 
		T.LastModifiedOnDate
	FROM  dbo.DnnProduct_Tabs AS T
		LEFT OUTER JOIN dbo.DnnProduct_ContentItems AS CI ON T.ContentItemID = CI.ContentItemID
GO
